﻿/*
输入：
20 30
5 18
17 13
4 5
19 16
16 18
12 13
3 14
7 13
10 11
1 13
5 10
4 17
5 14
8 13
3 1
5 3
13 16
15 9
6 14
4 9
15 13
4 0
10 9
12 5
1 9
10 18
6 11
2 5
12 7
7 4
输出：
0 1 2 3 4
*/
// N个顶点，M条边
string[] NMStr = Console.ReadLine().Split(" ");
int N = int.Parse(NMStr[0]);
int M = int.Parse(NMStr[1]);

// 记录入度
int[] inDegree = new int[N];
// 利用邻接表存储图
List<int>[] graph = new List<int>[N];
for (int i = 0; i < N; i++)
{
    graph[i] = new List<int>();
}

for (int i = 0; i < M; i++)
{
    string[] stStr = Console.ReadLine().Split(" ");
    int s = int.Parse(stStr[0]);
    int t = int.Parse(stStr[1]);
    graph[s].Add(t);
    inDegree[t]++;
}

// 记录结果
List<int> result = new List<int>();
Queue<int> queue = new Queue<int>();
for (int i = 0; i < inDegree.Length; i++)
{
    if (inDegree[i] == 0) queue.Enqueue(i);
}

while (queue.Count > 0)
{
    int index = queue.Dequeue();
    result.Add(index);
    for (int i = 0; i < graph[index].Count; i++)
    {
        inDegree[graph[index][i]]--;
        if(inDegree[graph[index][i]] == 0) queue.Enqueue(graph[index][i]);
    }
}

if (inDegree.Sum() > 0)
{
    Console.WriteLine(-1);
    return;
}
for (int i = 0; i < result.Count - 1; i++)
{
    Console.Write($"{result[i]} ");
}
Console.WriteLine(result[result.Count-1]);